Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support escaping | and & in utils.filter() #220

Merged
merged 1 commit into from
Jun 5, 2024
Merged

Support escaping | and & in utils.filter() #220

merged 1 commit into from
Jun 5, 2024

Conversation

psss
Copy link
Collaborator

@psss psss commented Jan 23, 2024

Add support for escaping boolean operators using the back slash character \ to allow for example regular expression grouping.

Pull Request Checklist

  • implement the feature
  • write the documentation
  • extend the test coverage

@psss psss added this to the 1.4 milestone Jan 23, 2024
@psss psss added the utils label Jan 23, 2024
Copy link
Collaborator

@lukaszachy lukaszachy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add examples how this should be used? I'm not sure the re.sub is correct but hard to tell.

@The-Mule
Copy link

@lukaszachy Any regexp where | is quite common, e.g. tmt test ls --filter 'name: (/setup\|/functional).*'.

@lukaszachy
Copy link
Collaborator

So re.sub doesn't work as expected, or? I'd assume that it intention is to 'undo' the escaping.

BTW it would be really good to see this covered in unit tests...

import re

>>> clause = re.split(r"\s*(?<!\\)\|\s*", r'foo\|bar|baz')[0]
>>> clause
'foo\\|bar'
>>> re.sub(r"\|", "|", clause)
'foo\\|bar'

@psss
Copy link
Collaborator Author

psss commented May 13, 2024

It's split of the filter() clause versus regular expression. See my comment in the related issue reported by @kkaarreell.

@psss
Copy link
Collaborator Author

psss commented May 14, 2024

Let's include escaping of & as well.

@martinhoyer
Copy link
Contributor

Found this PR only after commenting at #219 (comment)

@psss psss changed the title Add support for escaping | in utils.filter() Support escaping | and & in utils.filter() Jun 4, 2024
Add support for escaping boolean operators using the back slash
character `\` to allow for example regular expression grouping.
@psss psss self-assigned this Jun 5, 2024
@psss psss merged commit fe38c42 into main Jun 5, 2024
10 checks passed
@psss psss deleted the escape-operators branch June 5, 2024 08:21
@psss psss linked an issue Jun 5, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use parenthesis in --filter regexp
4 participants